vcTask
Simulation time can be consumed by using 'vcTasks' with 'await', but only within an 'async' function.
See in: Overview
Module: vcCore
Parent: -
Children -
Referenced by: vcCore.allTasks(), vcCore.anyTask(), vcCore.condition(), vcCore.delay(), ... (see more)
vcCore.allTasks()
vcCore.anyTask()
vcCore.condition()
vcCore.delay()
vcServoController.move()
vcServoController.moveJoint()
Properties
Learn how to use properties here. The properties are also inherited from the parent class.
| Name | Type | Access | Description |
| done | Boolean | R | Indicates whether the vcTask has completed its execution. |
| timeout | Real | R | Specifies the target timeout value for the vcTask. |
Methods
Learn how to use methods here. The methods are also inherited from the parent class.
| Name | Return Type | Parameters | Description |
| cancel | None | None | Cancels the vcTask execution and marks it as completed. |
| cancelled | None | Boolean | Indicates whether the vcTask has been cancelled. |
Example: Examples
"A collection of different ways to create a vcTask." import vcCore as vc comp = vc.getComponent() async def OnRun(): # wait delay await vc.delay(2) # returns vcTask print ("delay passed") # wait servo motion servo = comp.findBehavior('Servo Controller') servo.setJointTarget(0,100) await servo.move() # returns vcTask print ("servo motion passed") # wait signal value. Signal needs to be connected to the script signal = comp.findBehavior('BooleanSignal') await signal.waitFor(True) # returns vcTask print ("signal value received") # wait any event, e.g. vcNode.OnNodeTransform # gets triggered when link moved with e.g. Interact tool or by servo link = comp.findNode("Link_1") await link.OnNodeTransform.wait() # returns vcTask print ("OnNodeTransform event arrived")
Example: Wait Signals as Tasks
""" The script shows how to wait for change events from a pool of events. The events are first converted as vcTasks. """ import vcCore as vc async def OnRun(): comp = vc.getComponent() signal_1 = comp.findBehavior("BooleanSignal_1") signal_2 = comp.findBehavior("BooleanSignal_2") signal_3 = comp.findBehavior("BooleanSignal_3") e1_signal = comp.findBehavior("EmergencySignal_1") e1_time = 60 # seconds process_time = 10 # seconds while True: # recreate the awaitable tasks for the signals before the anyTask call t1 = signal_1.OnSignal.wait() # Converts OnSignal event to an awaitable task t2 = signal_2.OnSignal.wait() t3 = signal_3.OnSignal.wait() e1 = e1_signal.OnSignal.wait() await vc.anyTask([t1,t2,t3,e1]) # wait for any of the awaitable tasks to complete if e1_signal.Value: # emergency routine vc.delay(e1_time) if signal_1.Value == True and signal_2.Value and signal_3.Value: # start process vc.delay(process_time)
Example: Async Advanced Example
""" An example of two asynchronously driven joint routines """ import vcCore as vc comp = vc.getComponent() servo_blue = comp.findBehavior('ServoController2') servo_red = comp.findBehavior('ServoController1') def get_next_blue_task(blue_i): if blue_i == 0: return servo_blue.moveJoint(0, 100) elif blue_i == 1: return vc.delay(1) elif blue_i == 2: return servo_blue.moveJoint(0, 0) else: print ("blue done") return None def get_next_red_task(red_i): if red_i == 0: return servo_red.moveJoint(0, 500) elif red_i == 1: return vc.delay(1) elif red_i == 2: return servo_red.moveJoint(0, 0) else: print ("red done") return None async def OnRun(): tasks = [] red_i = 0 blue_i = 0 red_t = get_next_red_task(red_i) blue_t = get_next_blue_task(blue_i) tasks = [red_t, blue_t] while True: await vc.anyTask(tasks, autoCancel=False) if red_t and red_t.done(): red_i += 1 red_t = get_next_red_task(red_i) if blue_t and blue_t.done(): blue_i += 1 blue_t = get_next_blue_task(blue_i) tasks = [] if red_t: tasks.append(red_t) if blue_t: tasks.append(blue_t) if len(tasks) == 0: return